package com.itheima.question.controller;

import com.itheima.PageVo;
import com.itheima.Result;
import com.itheima.admin.dto.PageDto;
import com.itheima.admin.dto.QuestionDto;
import com.itheima.admin.vo.QuestionVo;
import com.itheima.common.contants.RedisPicConstants;
import com.itheima.question.service.IQuestionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/question")
@Api(value = "添加问题接口",tags = "admin_user",description = "用于实现问题添加")
public class QuestionController {
    @Autowired
    private IQuestionService questionService;

    @PostMapping("/add")
    @ApiOperation("添加问题")
    public Result addQuestion(@RequestBody QuestionDto questionDto){
        boolean result = questionService.addQuestion(questionDto);
        return new Result(result,result?"添加问题成功":"添加问题失败",null);
    }

    @PostMapping("/list")
    @ApiOperation("分页显示题目列表")
    public PageVo<QuestionVo> queryByPage(@RequestBody PageDto pageDto){
        return questionService.queryByPage(pageDto);
    }
    @GetMapping("/{id}")
    @ApiOperation("根据题目ID查找题目信息")
    public QuestionDto queryById(@PathVariable String id){
        return questionService.queryById(id);
    }
}
